from django.http import JsonResponse
from django.shortcuts import render


# Create your views here.
from strategy.strategy import MaStrategy


def ma_html(request):
    """返回均线策略的form表单页面"""
    return render(request, 'ma_html.html', context=locals())


def ma_strategy(request):
    """均线策略数据接收及处理，并返回处理结果"""
    req_body = request.POST
    stockcode = req_body.get('stockcode')
    ma = int(req_body.get('ma'))
    startdate = req_body.get('startdate')
    money = int(req_body.get('money'))
    mastrategy = MaStrategy()
    item = mastrategy.run(stockcode, ma, startdate, money)
    print(item)
    return render(request, 'strategy_ret.html', locals())


def index(request):
    """返回首页"""
    return render(request, 'index.html', context=locals())
